package com.sskj.ffex.p.activity;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.sskj.ffex.m.HttpConfig;
import com.sskj.ffex.m.bean.AddressList;
import com.sskj.ffex.m.bean.HttpData;
import com.sskj.ffex.m.http.JsonCallBack;
import com.sskj.ffex.p.base.BasePresenter;
import com.sskj.ffex.utils.ToastUtil;
import com.sskj.ffex.v.activity.CashAddressAddActivity;
import com.sskj.ffex.v.activity.CashAddressListActivity;

/**
 * Created by Administrator on 2018/4/2 0002.
 */

public class CashPresenter extends BasePresenter {

    public void requestAddressList(String account) {
        OkGo.<HttpData<AddressList>>post(HttpConfig.BASE_URL + HttpConfig.ADDRESS_LIST)
                .params("account", account)
                .execute(new JsonCallBack<HttpData<AddressList>>(this) {

                    @Override
                    public void _onSuccess(Response<HttpData<AddressList>> response) {
                        HttpData<AddressList> body = response.body();
                        ((CashAddressListActivity)mView).onResponseCashAddressListSuccess(body.getData());
                    }
                });
    }

    public void requestAddAddress(String address, String notes, String account, String type) {
        OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.ADDRESS_ADD)
                .params("qiaobao_url", address)
                .params("notes", notes)
                .params("account", account)
                .params("type", type)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void _onSuccess(Response<HttpData> response) {
                        HttpData body = response.body();
                        ToastUtil.showShort(body.msg);
                        ((CashAddressAddActivity)mView).onResponseCashAddressAddSuccess();
                    }
                });
    }

    /**
     * 删除提现地址
     * @param type 0:eth ;  1: btc
     * @param position
     * @param id
     */
    public void requestDelite(int type, int position, String id) {
        OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.ADDRESS_ADD)
                .params("id", id)
                .params("act", "del")
                .execute(new JsonCallBack<HttpData>(this) {

                    @Override
                    protected void _onSuccess(Response<HttpData> response) {
                        ToastUtil.showShort(response.body().msg);
                        ((CashAddressListActivity)mView).onDeliteSuccess(type, position);
                    }
                });
    }
}
